﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Collections.Specialized;
using System.Xml.Linq;

using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Configuration;

public partial class Controls_ucServersList : System.Web.UI.UserControl
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
        LoadData();
        
    }   

    public void LoadData()
    {
        lblTime.Text =string.Format("Welcome, {1} Last Update: {0}",  DateTime.Now.ToString(),HttpContext.Current.User.Identity.Name);

        DataList1.DataSource = GetServers();
        DataList1.DataBind();
    }

    private List<ServerInfo> GetServers()
    {
        //List<ServerInfo> _serverInfo = new List<ServerInfo>();

        //DataContext db = new DataContext(ConfigurationManager.ConnectionStrings["SQLExpressCon"].ConnectionString); //Server.MapPath("~/App_Data/ServerDB.mdf"));
        //Table<server> server = db.GetTable<server>();
  
            //IQueryable<server> servQuery = from serv in server select serv;
            //foreach (server serv in servQuery)
            //{
            //    if (serv.status.TrimEnd() == "Y")
            //    {
            //        _serverInfo.Add(new ServerInfo(serv.serverName, serv.userName, serv.passWord));
            //  }
            //}
        ServerDBLinqDataContext ctx = new ServerDBLinqDataContext();

        var Query = (from servers in ctx.Servers
                    where servers.status == "Y"
                     select new ServerInfo { serverName = servers.serverName, userName = servers.userName, passWord = servers.passWord }).ToList();

        return Query; 
    }

    //[Table(Name = "dbo.Servers")]
    //public class server
    //{
    //    private int _key;
    //    [Column(IsPrimaryKey = true, Storage = "_key")]
    //    public int Key
    //    {
    //        get { return _key; }
    //        set { _key = value;} 
    //    }
    //    private string _serverName;
    //    [Column(Storage = "_serverName")]
    //    public string serverName
    //    {
    //        get { return _serverName; }
    //        set { _serverName = value; }
    //    }
    //    private string _userName;
    //    [Column(Storage = "_userName")]
    //    public string userName
    //    {
    //        get { return _userName; }
    //        set { _userName = value; }
    //    }
    //    private string _passWord;
    //    [Column(Storage = "_passWord")]
    //    public string passWord
    //    {
    //        get { return _passWord; }
    //        set { _passWord = value; }
    //    }
    //    private string _status;
    //    [Column(Storage = "_status")]
    //    public string status
    //    {
    //        get { return _status; }
    //        set { _status = value; }
    //    }
    //}
}